package com.chaos.gateway.config.filter;

import cn.hutool.core.util.IdUtil;
import com.chaos.framework.model.constant.Constants;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;
import reactor.core.publisher.Mono;

//@Component
//@Slf4j
//@Order(Integer.MIN_VALUE)
public class GatewayTraceIdReqFilter implements WebFilter {

    @Override
    public @NonNull Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
        String getaWay = IdUtil.simpleUUID();
        exchange.getRequest().mutate().header(Constants.TRACE_ID, getaWay).build();
        return chain.filter(exchange);
    }

}
